package com.shensi.adminCollect.controller.station;

import com.shensi.common.core.controller.BaseController;
import com.shensi.common.core.domain.AjaxResult;
import com.shensi.common.redis.service.RedisCache;
import com.shensi.adminCollect.common.utils.StringUtils;
import com.shensi.adminCollect.service.customer.ICustomerCardUseRecordService;
import com.shensi.adminCollect.domain.station.PayOrder;
import com.shensi.adminCollect.service.station.*;
import com.shensi.adminCollect.domain.system.HttpUtils;
import com.shensi.adminCollect.service.system.ISysDeptService;
import com.shensi.adminCollect.service.system.ISysUserService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api("订单信息")
@RestController
@RequestMapping("/syncOrder")
public class OrderSyncController extends BaseController {
    @Autowired
    private IPayOrderService payOrderService;
    @Autowired
    private ISysDeptService deptService;

    @Autowired
    private IPayOrderHistoryService payOrderHistoryService;
    @Autowired
    private IStationDeviceManageService stationDeviceManageService;

    @Autowired
    private IStationBalanceChangeService stationBalanceChangeService;


    @Autowired
    private IStationService stationService;
    @Autowired
    private ISysUserService userService;

    @Autowired
    private ICustomerCardUseRecordService customerCardUseRecordService;

    @Resource
    private RedisCache redisCache;

    @Resource
    private InvoiceService invoiceService;

    @Value("${qujia.payBaseUrl}")
    private String payBaseUrl;


    @PostMapping("/updateOrder/{timestamp}/{sign}")
    public AjaxResult edit(@RequestBody PayOrder payOrder) {
        return toAjax(payOrderService.updatePayOrderByOrderNo(payOrder));
    }

    @GetMapping(value = "/{orderId}/{timestamp}/{sign}")
    public AjaxResult getInfo(@PathVariable("orderId") String orderId) {
        return AjaxResult.success(payOrderService.selectPayOrderById(Long.parseLong(orderId)));
    }

    @PostMapping("/addOrder/{timestamp}/{sign}")
    public AjaxResult add(@RequestBody PayOrder payOrder) {
        return payOrderService.insertPayOrderForStar(payOrder);
    }

    @PostMapping("/dzkPay/{timestamp}/{sign}")
    public AjaxResult dzkPay(@RequestParam String ordNo, String couponUserId) {
        if(StringUtils.isEmpty(ordNo)){
            AjaxResult.error("订单号不能为空");
        }
        String url=payBaseUrl+"/dzkPaySetV2?ordNo="+ordNo;
        String result="";
        try {
            result = HttpUtils.connectGetUrl(url);
        } catch (Exception e) {
            AjaxResult.error(e.getMessage());
        }
        return AjaxResult.success(result);
    }
}
